// #include <iostream>
// #include <thread>
// #include <chrono>

#include <stdio.h>
#include <stdlib.h>

#include <ctype.h>
#include <time.h>
#include <unistd.h>

typedef struct timespec timespec;

int isNumber ( char* number );

int main ( int argc, char** argv ) {

    if ( argc < 2 ) {
        printf( "USAGE:\r\n" );
        printf( " usleep <Number of microseconds>\r\n" );
        return -1;
    }

    if ( isNumber( argv[1] ) ) {
        printf( "Please input a number string.\r\n" );
        return -1;
    }

    timespec n_sleep_;
    int time_ = atoi(argv[1]);
    // std::cout << "usleep time is " << time_ << std::endl;

    n_sleep_.tv_nsec = 1000L;
    nanosleep( &n_sleep_, NULL );
    // std::this_thread::sleep_for(std::chrono::microseconds(time_));
    // std::this_thread::sleep_for(std::chrono::seconds(time_));
    // std::cout << "usleep time is " << time_ << std::endl;
}

int isNumber ( char* number ) {

    int i = 0;
    for ( ; number[i] != 0; i++ ) 
        if ( isdigit( number[i] ) == 0 ) 
            return -1;

    return 0;
}
